import { PluginType, TriggerPluginType } from './interface';
import plugin from './plugin';

const triggerPlugin = (pluginName: PluginType, type: string, config: any) => {
  // @ts-ignore
  return plugin[pluginName](type, config);
};

export const triggerTableCellRender = (type: TriggerPluginType, record: any) => {
  return type ? triggerPlugin('renderTableCell', type, record) : record;
};

export const triggerTableSelectedRows = (type: TriggerPluginType, selectedRows: any) => {
  return type ? triggerPlugin('convertTableSelectedRows', type, selectedRows) : selectedRows;
};

export const triggerConvertSearchParams = (type: TriggerPluginType, params: any) => {
  return type ? triggerPlugin('convertSearchParams', type, params) : params;
};

export const triggerConvertDataSource = (type: TriggerPluginType, data: any) => {
  return type ? triggerPlugin('convertDataSource', type, data) : data;
};

export const triggerConvertDisplayValue = (type: TriggerPluginType, data: any) => {
  return type ? triggerPlugin('convertDisplayValue', type, data) : data;
};

export const triggerTableCheckboxRowProps = (type: TriggerPluginType, data: any) => {
  return type ? triggerPlugin('tableCheckboxRowProps', type, data) : {};
};

export const triggerConvertSubmitParams = (type: TriggerPluginType, data: any) => {
  return type ? triggerPlugin('convertSubmitParams', type, data) : {};
};

export const triggerConvertDetailValuesType = (type: TriggerPluginType, data: any) => {
  return type ? triggerPlugin('convertDetailValues', type, data) : {};
};
